﻿using PGMHelper;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace CouplingBeamStiff
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
            this.Structure = new Structure();
        }
        /// <summary>
        /// 有限元模型
        /// </summary>
        private Structure Structure { get; set; }
        /// <summary>
        /// 求位移
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CSWGetDButton_Click(object sender, EventArgs e)
        {
            GlobalVar.Initial();
            Structure structure = ((Control)sender).Name.Contains("CCSW") ? this.SetupCoupledShearWall() : this.SetupNewCoupledShearWall();
            var value = structure.GetMaxResponse();
            MessageBoxExtern.Asterisk(string.Format(((Control)sender).Name.Contains("CCSW")? "中梁为梁单元的联肢剪力墙顶点位移(mm): {0}" : "中梁为壳单元的联肢剪力墙顶点位移(mm): {0}", value));
        }
        private Structure SetupCoupledShearWall()
        {
            double lifeWallWidth = Convert.ToDouble(this.LeftWallWidthTextbox.Text);
            double rightWallWidth = Convert.ToDouble(this.RightWallWidthTextbox.Text);
            double storyHeight = Convert.ToDouble(this.StoryHeightTextbox.Text);
            double middleBeamWidth = Convert.ToDouble(this.MiddleBeamWidthTextbox.Text);
            double middleBeamHeight = Convert.ToDouble(this.MiddleBeamHeightTextbox.Text);
            double storyNumber = Convert.ToDouble(this.StoryNumberTextbox.Text);
            var structure = new Structure();
            for(int i = 0; i < storyNumber; i++)
            {
                structure.AddCoupledShearWall(lifeWallWidth, storyHeight, middleBeamWidth, middleBeamHeight, rightWallWidth);
            }
            return structure;
        }
        private Structure SetupNewCoupledShearWall()
        {
            double lifeWallWidth = Convert.ToDouble(this.LeftWallWidthTextbox.Text);
            double rightWallWidth = Convert.ToDouble(this.RightWallWidthTextbox.Text);
            double storyHeight = Convert.ToDouble(this.StoryHeightTextbox.Text);
            double middleBeamWidth = Convert.ToDouble(this.MiddleBeamWidthTextbox.Text);
            double middleBeamHeight = Convert.ToDouble(this.MiddleBeamHeightTextbox.Text);
            double storyNumber = Convert.ToDouble(this.StoryNumberTextbox.Text);
            var structure = new Structure();
            for(int i = 0; i < storyNumber; i++)
            {
                structure.AddNewCoupledShearWall(lifeWallWidth, storyHeight, middleBeamWidth, middleBeamHeight, rightWallWidth);
            }
            return structure;
        }
    }
}
